<?php

/**
 * Description of class_generator
 * PHP class that incorpores the main methods to generate HTML from template.
 * 
 *
 * @author Guillermo
 */

 include("Core/class_template.php");
 include("Core/class_XML.php");
 
class Generator {
    
    private $template;
    private $elements;
    private $Xml;
   
     /**
      * Contructor of the class Generator. It initializes the atribute template
      * and it load in memory the template that representes a HTML doc.
      * @param type $template
      */
    function Generator($template){
        $this->template= new TemplateHTML;
        $this->template->LoadTemplate($template);
    }
    
    /**
     * This method generates a new HTML doc from the initial template with
     * the data from the file $dataXML.
     * @param type $dataXML
     */
    function Generate($dataXML){
        $this->Xml = new XML($dataXML);
        $this->elements = $this->Xml->obtainElements();
        
        //Foreach that looks all elements and changes the data
        foreach ($this->elements as &$element) {
            $this->template->ChangeData($element,$this->Xml->obtainData($element));
            }
        //Publish the template     
        $this->template->PublishTemplate();
    }
    
    /**
     * ChangeData only changes one data with one key from the HTML template.
     * @param type $key
     * @param type $data
     */
    function ChangeData($key,$data){
        $this->template->ChangeData($key,$data);
    }
    
    /**
     * Publish the template.
     */
    function Publish(){
         $this->template->PublishTemplate();
    }
    
}

?>
